<?php
	class LoginAction extends CommonAction{

		function _initialize(){
		}

		public function index(){
			if ($this->isLogin()){
				$this->assign('jumpUrl', '__APP__/');
				$this->assign('waitSecond', 1);
				$this->success('已经登录!');
			}else{
				$this->display();
			}
		}

		public function checkLogin(){
			import('@.Common.Hash');
			$user = M('user', CommonModel);
			$username = $_POST['user'];
			//dump($username);
			$password = $_POST['pass'];
			//dump($password);
			$result = $user->where(Array('name' => $username, 'password' => $password))->find();
			//dump($result);
			$username = $_POST['user'];
			$this->assign('user', $username);
			$this->assign('pass', $password);
			if ($result){
				session_regenerate_id();
				Session::start();
				Session::set('user', $username);
				$this->assign('jumpUrl', '__APP__/');
				$this->assign('waitSecond', 1);
				$this->success('登录成功');
			}else{
				$this->error('登录失败');
			}
		}

		public function logout(){
			Session::destroy();
			session_destroy();
			$this->assign('jumpUrl', '__APP__/login/');
			$this->assign('waitSecond', 1);
			$this->success('注销成功');
		}

		public function status(){
			import('@.Common.Hash');
			dump(session_id());
			dump($_SESSION);
			$username = Session::get('user');
			dump(Hash::hash_passwd($username));
			$this->display();
		}

		public function setsid(){
			session_destroy();
			$sid = $_GET['sid'];
			session_id($sid);
			Session::id($sid);
			$this->assign('jumpUrl', '__APP__/login/status/');
			$this->assign('waitSecond', 1);
			$this->success('登录成功');
		}

		public function changePasswd(){
			$user = M('user', CommonModel);
			$username = $_POST['user'];
			dump($username);
			$password = $_POST['pass'];
			dump($password);
			if ($username){
				$result = $user->where(Array('name' => $username))->data(Array('password' => $password))->save();
				dump($result);
			}
			$this->display('status');
		}

		private function isLogin(){
			return Session::is_set('user');
		}

	}
